Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: calculate timestamp and block number tacking account execution mode (execution vs validate) #401

Merged
merged 12 commits into from
Oct 16, 2024

Conversation

HermanObst
Copy link
Collaborator

@HermanObst HermanObst commented Oct 9, 2024

Problem: Some blocks were failing because the get_block_number and get_block_timestamp were retrieving different values than the SNOS was expecting.
This is related to the fact that two modes of execution exist: Execute (were the expected behaviour is to get the actual block number and timestamp) and Validate (were the expectation is to get an rounding of them)

Fix: modify the given syscalls to fetch the blockInfo from the ExecutionInfo struct from SNOS

@@ -136,9 +137,11 @@ where
let syscall_handler = self.deprecated_syscall_handler.read().await;

let block_number = syscall_handler.block_info.block_number;
let rounded_block_number = (block_number.0 / VALIDATE_BLOCK_NUMBER_ROUNDING ) * VALIDATE_BLOCK_NUMBER_ROUNDING;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use prev_multiple_of instead?

@@ -15,6 +15,7 @@ use crate::cairo_types::syscalls::{
TxInfo,
};
use crate::starknet::starknet_storage::PerContractStorage;
use crate::execution::constants::{VALIDATE_BLOCK_NUMBER_ROUNDING, VALIDATE_TIMESTAMP_ROUNDING};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already discussed this, but these should be able to come from the constants in cairo-lang. We should do that if at all possible, but if not we should leave a comment about that here.

let execution_info_ptr = execution_helper
.call_execution_info_ptr
.ok_or(HintError::SyscallError("Execution info pointer not set".to_string().into_boxed_str()))?;
let block_info_pointer = vm.get_relocatable((execution_info_ptr + ExecutionInfo::block_info_offset())?)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nit: we usually _ptr instead of _pointer

let tx_version = TransactionVersion::ZERO;
let tx_version = TransactionVersion::THREE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also curious about this.

Copy link
Collaborator

@notlesh notlesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left a couple small nits.

Also, it might be good to document the behavior of the validation mode briefly in the functions if it seems useful.

Copy link
Collaborator

@whichqua whichqua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

let tx_version = TransactionVersion::ZERO;
let tx_version = TransactionVersion::THREE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also curious about this.

@HermanObst
Copy link
Collaborator Author

Thanks @notlesh and @whichqua. Yes, the tx version = 3 was something I change while exploring possible cases and then I forget. fixed :)

@HermanObst HermanObst merged commit eb0c4f5 into main Oct 16, 2024
6 checks passed
@HermanObst HermanObst deleted the herman/fix-timestamp branch October 16, 2024 01:03
@HermanObst HermanObst changed the title fix: timestamp and block number mismatch fix: calculate timestamp and block number tacking account execution mode (execution vs validate) Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants